package darknet.application.chat.impl.net.message;

import darknet.core.impl.net.AbstractMessage;
import darknet.core.spec.net.MessageHeader;
import darknet.core.spec.net.Node;

/**
 * A Private Message (MP).
 * 
 * A private message is a message for only one person.
 *
 * This message is sent between the a session start message and a session
 * exit message.
 * 
 * @author Yoyo
 */
public class PrivateMessage extends AbstractMessage {

    /** The text message */
    private String text;
    
    /**
     * Initialise a new Private Message.
     * 
     * @param text The message content
     * @param from The writer
     * @param to   The receiver  
     */
    public PrivateMessage(MessageHeader header, Node from, Node to, String text) {
	super(header, from, to);
	
	if(text == null || text.length() == 0) {
	    throw new IllegalArgumentException("message is invalid");
	}
	this.text = text;
    }

    /**
     * Get the text message.
     * @return
     */
    public String getText() {
	return text;
    }

    @Override
    public String toString() {

        StringBuilder builder = new StringBuilder("PrivateMessage[");
        builder.append("super=");
        builder.append(super.toString());
        builder.append(", ");
        builder.append("text=");
        builder.append(text);
        builder.append("]");

        return builder.toString();
    }
}
